package com.qincji.webviewbrowser;

import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

/**
 * 描述：日志打印
 * 作者：mac on 2021/6/17 08:15
 * 邮箱：xhunmon@126.com
 */
public final class Logs {
    public static final int DEBUG = 3;
    public static final int INFO = 4;
    public static final int WARN = 5;
    public static final int ERROR = 6;
    public static final int FATAL = 7;
    public static final int LOG_APP = 0;

    public static final int NONE = 8;

    private static int LOG_LEVEL = LOG_APP;
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(HiLog.LOG_APP, 0x00101, "Logs");
    private static final String LOG_FORMAT = "%{public}s: %{public}s";

    private Logs() {
    }

    public static void setLevel(int level) {
        LOG_LEVEL = level;
    }

    public static boolean isCanLog(int level) {
        return level >= LOG_LEVEL;
    }

    public static void d(String tag, String msg) {
        if (DEBUG >= LOG_LEVEL) {
            HiLog.debug(LABEL_LOG, LOG_FORMAT, tag, msg);
        }
    }

    public static void i(String tag, String msg) {
        if (INFO >= LOG_LEVEL) {
            HiLog.info(LABEL_LOG, LOG_FORMAT, tag, msg);
        }
    }

    public static void w(String tag, String msg) {
        if (WARN >= LOG_LEVEL) {
            HiLog.warn(LABEL_LOG, LOG_FORMAT, tag, msg);
        }
    }

    public static void e(String tag, String msg) {
        if (ERROR >= LOG_LEVEL) {
            HiLog.error(LABEL_LOG, LOG_FORMAT, tag, msg);
        }
    }

    public static void f(String tag, String msg) {
        if (FATAL >= LOG_LEVEL) {
            HiLog.fatal(LABEL_LOG, LOG_FORMAT, tag, msg);
        }
    }
}
